package com.alibaba.citrus.cr.mn.order.center.facade.function.asynctask;

import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.lattice2.epoch.file.dto.OssConfig;
import com.alibaba.lattice2.epoch.file.service.EpochOssConfigService;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zhangxiaorui
 * @ClassName AsyncTaskCreateOssService
 * @description: TODO
 * @date 2023/05/18 16:48
 * @version: 1.0
 */
@Component
public class AsyncTaskOssService {
    private static final Log log = Log.getLogger(AsyncTaskOssService.class);

    @Autowired(required = false)
    private EpochOssConfigService epochOssConfigService;

    public AsyncTaskOssProcessor getOssClient(String ossCode) {
        OssConfig tenantOssConfig = epochOssConfigService.getTenantOssConfig(ossCode);
        OSS ossBuild = new OSSClientBuilder()
                .build(tenantOssConfig.getEndpoint(),
                        tenantOssConfig.getAccessKeyId(),
                        tenantOssConfig.getAccessKeySecret());

        AsyncTaskOssProcessor uploadProcess = new AsyncTaskOssProcessor();
        uploadProcess.setOssClient(ossBuild);
        return uploadProcess;
    }
}
